package io.renren.modules.picApproval.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.picApproval.entity.MediaFileEntity;
import io.renren.modules.picApproval.service.MediaFileService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.Query;
import io.renren.common.utils.R;


/**
 * 
 * 
 * @author wxy
 * @email sharonwang_xy@163.com
 * @date 2018-10-29 14:16:30
 */
@RestController
@RequestMapping("picApproval/mediafile")
public class MediaFileController {
	@Autowired
	private MediaFileService mediaFileService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("picApproval:mediafile:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<MediaFileEntity> mediaFileList = mediaFileService.queryList(query);
		int total = mediaFileService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(mediaFileList, total, query.getLimit(), query.getCurrPage());
		
		return R.ok().put("page", pageUtil);
	}

	/**
	 * 根据shootId列出信息
	 *
	 */
	@RequestMapping("/listByShootId/{shootId}")
	@RequiresPermissions("picApproval:mediafile:info")
	public R listByShootId(@PathVariable("shootId") String shootId){
		//查询列表数据

		List<MediaFileEntity> mediaFileList = mediaFileService.queryListByShootId(shootId);

		return R.ok().put("mediaFileList", mediaFileList);
	}


	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{mediaId}")
	@RequiresPermissions("picApproval:mediafile:info")
	public R info(@PathVariable("mediaId") Long mediaId){
		MediaFileEntity mediaFile = mediaFileService.queryObject(mediaId);
		
		return R.ok().put("mediaFile", mediaFile);
	}
	
	/**
	 * 保存
	 */
	@RequestMapping("/save")
	@RequiresPermissions("picApproval:mediafile:save")
	public R save(@RequestBody MediaFileEntity mediaFile){
		mediaFileService.save(mediaFile);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@RequestMapping("/update")
	@RequiresPermissions("picApproval:mediafile:update")
	public R update(@RequestBody MediaFileEntity mediaFile){
		mediaFileService.update(mediaFile);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("/delete")
	@RequiresPermissions("picApproval:mediafile:delete")
	public R delete(@RequestBody Long[] mediaIds){
		mediaFileService.deleteBatch(mediaIds);
		
		return R.ok();
	}
	
}
